package com.hjq.fcloud.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringHelper {

    public static boolean isStringNull(String s) {
        return s == null || s.equals("") || s.equals("null") || s.equals("NULL");
    }

    public static boolean isNumber(String str) {
        if (isStringNull(str)) return false;
        Pattern pattern = Pattern.compile("-?[0-9]+\\.?[0-9]*");
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }

    /**
     * 字符串如果是数字则抹0
     */
    public static String roundStr(String number){
        try {
            if (isNumber(number) && number.indexOf(".") > 0) {
                // 正则表达
                number = number.replaceAll("0+?$", "");// 去掉后面无用的零
                number = number.replaceAll("[.]$", "");// 如小数点后面全是零则去掉小数点
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return number;
    }
}
